<?php
/* these are avalible via the sessioninclude.php
$catdebug = 0; //Set to 1 to crank to echo my debug stuff
$mysitebase = "http://kopykat.horseoff.com/";
$mysitefilepath = "http://copycat.horseoff.com/kopykat/";
$mysitename = "KopyKat";
$mysitenavigation = $mysitebase . "server/user/navigation.php";
$userManagePage = $mysitebase . "server/user/manage.php";
$userConfirmPage = $mysitebase . "server/user/confirm.php";
$userLogoutPage = $mysitebase . "server/user/logout.php";
$userSLInstallPage = $mysitebase . "server/user/kopykatinstall.php";
$mysitesilverlightinstalldir = $mysitebase ;
$kkserver = $mysitebase;
$kkspeak = $mysitebase . "server/pastehere.php";
$kklisten = $mysitebase . "server/copyhere.php?KopyKatlistenname=";
*/
/* Below is used to pass to localstore silverlight
<div id="kopykatuid" value="<?php echo '$datadump["sessions"][1]["uid"]'; ?>"><?php echo '$datadump["sessions"][1]["uid"]'; ?></div>
<div id="kopykatuemail" value="<?php echo '$datadump["sessions"][1]["email"]'; ?>"><?php echo '$datadump["sessions"][1]["email"]'; ?></div>
<div id="kopykatserver" value="<?php echo "$kkserver"; ?>"><?php echo "$kkserver"; ?></div>
<div id="kopykatspeak" value="<?php echo "$kkspeak"; ?>"><?php echo "$kkspeak"; ?></div>
<div id="kopykatlisten" value="<?php echo "$kklisten"; ?>"><?php echo "$kklisten"; ?></div>
*/
/* the DB vars are set in session include so we can use
$linkhost = "localhost";
$linkdb = "kopykat";
$linkuser = "root";
$linkpwd = "";
*/
/* Session stuff is set in session... we can use them
// remember to set the rpxnow callback to the loginconfirm it your using the OpenID login stuff
// Go setup again cause we may have cleard the session above saftey will be off so we regen the session ID.
$mysession = session_id();
if ($mysession == '') session_start();
if (!isset($_SESSION['safety']))
{
    session_regenerate_id(true);
    $_SESSION['safety'] = true;
    header("Location:login.php");
}
$mysession = session_id();
if ($mysession == '') session_start();
$_SESSION['sessionid'] = session_id();

if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
*/

/* ===datadump structure===
Intent: Session based data structure extraced from database
Rules: A user is in a session that has authentication.
*/
/* AND... we can use the datadump
$datadump = array();
$datadump['status'] = 'noData';
if(isset($_SESSION['sessionid'])) {
	$datadump['sessionID'] = $mysession;
	$datadump['status'] = 'hasSession';
	$link = mysql_connect($linkhost,$linkuser,$linkpwd) or die('Cannot connect to the DB');
	mysql_select_db($linkdb,$link) or die('Cannot select the DB');
	// grab the session data from the db 
	$query = "SELECT * FROM kksession WHERE sid = '$mysession'";	
	$result = mysql_query($query,$link) or die('Errant query:  '.$query);
	if(mysql_num_rows($result)) {
		$datadump['status'] = 'hasSessionData';
		$i=0;
		while($datarow = mysql_fetch_assoc($result)) {
			$i++;
			$datadump['sessions'][$i] = $datarow;
		}
		$datadump['sessions']['sessionCount'] = $i;
	} else {
		$datadump['sessions'] = array('error'=>'No session data found');
	}
	//$query = "SELECT post_title, guid FROM wp_posts WHERE post_author = $user_id AND post_status = 'publish' ORDER BY ID DESC LIMIT $number_of_posts";
	// grab the user data from the db if we have a session 
	if($datadump['sessions']['error'] == '') {
		$query = "SELECT a.provider, a.identifier, a.URL, a.email, a.name FROM kkauth a, kksession b WHERE a.kkuidhash = b.uid AND b.sid = '$mysession'";
		$result = mysql_query($query,$link) or die('Errant query:  '.$query);
		// create one master array of the records 
		if(mysql_num_rows($result)) {
			$datadump['status'] = 'hasUserData';
			$i = 0;
			while($datarow = mysql_fetch_assoc($result)) {
				$i++;
				$datadump['users'][$i] = $datarow;
			}
			$datadump['users']['userCount'] = $i;
		} else {
			$datadump['users'] = array('error'=>'No user data found');
		}
	}
	// disconnect from the db 
	@mysql_close($link);
}
*/
/* We want to create a new datastructure right now lets just fake.
Eventually, we want to go get a chunk of history and meta control data
and pass that down to the UI. */
/* Below is the current structure used in the silverlight app
  $datahistory array Structure:
	kkcbpnt - KopyKat ClipBoard PoiNTer - current next new key for clipboardpointer
	kksppnt - KopyKat clipboard SPeak PoiNTer - current pointer of the speaking
	kklspnt - KopyKat clipboard LiSten PoiNTer - current pointer of the listening
*/
$datahistory = array('kkcbpnt' => '4', 'kksppnt' => '0', 'kklspnt' => '0', '0' => 'Historyclip00', '1' => 'Historyclip01', '2' => 'Historyclip02', '3' => 'Historyclip03');

?> 